package com.learn.hibernatevalidator.chapter04.complete;

import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @author: liyf
 * @create: 2025-01-04 22:43
 **/
@Data
public class Car {

    /**
     * 使用默认错误信息
     */
    @NotNull
    private String manufacturer;

    /**
     * 自定义错误信息
     * ${validatedValue}：表示当前值
     * {min}: mix的值
     * {max}: max的值
     */
    @Size(
            min = 2,
            max = 14,
            message = "The license plate '${validatedValue}' must be between {min} and {max} characters long"
    )
    private String licensePlate;

    /**
     * 自定义消息+表达式
     * ${表达式}
     */
    @Min(
            value = 2,
            message = "There must be at least {value} seat${value > 1 ? 's' : ''}, current: ${validatedValue}"
    )
    private int seatCount;

    /**
     * 自定义消息 + 格式化
     */
    @DecimalMax(
            value = "350",
            message = "The top speed ${formatter.format('%1$.2f', validatedValue)} is higher " +
                    "than {value}"
    )
    private double topSpeed;

    @DecimalMax(value = "100000", message = "Price must not be higher than ${value}")
    private BigDecimal price;

    public Car(
            String manufacturer,
            String licensePlate,
            int seatCount,
            double topSpeed,
            BigDecimal price) {
        this.manufacturer = manufacturer;
        this.licensePlate = licensePlate;
        this.seatCount = seatCount;
        this.topSpeed = topSpeed;
        this.price = price;
    }
}
